package Leetcode.ArrayAndLinkedList.PlusOne66;

public class Solution2 {
    public int[] plusOne(int[] digits) {
        int len = digits.length;
        for (int i = len - 1; i >= 0; i++) {
            digits[i]++;
            int num = digits[i] % 10;
            if(num != 0) {
                return digits;
            }
            digits[i] = 0;
        }
        digits = new int[len + 1];
        digits[0] = 1;
        return digits;
    }
}


/**
 * int len = digits.length;
 * for (int i = len - 1; i >= 0; i--) {
 * digits[i]++;
 * if (digits[i] % 10 != 0) {
 * return digits;
 * }
 * digits[i] = 0;
 * }
 * digits = new int[len + 1];
 * digits[0] = 1;
 * return digits;
 */